package com.example.untils;

import com.example.model.pojo.NiuMaBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
public class EmailUntil {
    @Autowired
    private NiuMaBean niuMaBean;
    @Autowired
    private JavaMailSender javaMailSender;
    public    void sendEmail(String toEmail,String code)
    {
        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setSubject(niuMaBean.getEmailTitle());
        //设置邮箱的正文内容
        msg.setText(" [牛马娱乐] 验证码："+code+" , 5分钟内有效");
        //设置邮箱的发送方,应该要和application-dev.yml中的邮箱保持一致
        msg.setFrom(niuMaBean.getEmail());
        msg.setTo(toEmail);

        javaMailSender.send(msg);
    }
    public Integer GCode(){
        return  (int) (Math.random()*10000+10000);
    }
}
